package ui;

/**
 * EDCTableAnalyzer
 * Table view to show results of analysis, one line per DTD and one row per property checked
 * -1 lines represent parsing errors
 */
import java.io.File;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

import utils.EDCUtils;

public class EDCTableAnalyzeModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private boolean DEBUG = false;
	
	//Column names
	private String[] columnNames = {"File name",
			"Bad lines","ANY","EMPTY","Redudancy","Bad choices"};
	
	//data
	private Vector<Vector<Object>> data;
	
	/**
	 * Constructor
	 */
	public EDCTableAnalyzeModel() {
		data = new Vector<Vector<Object>>();
	}
	
	/**
	 * @return
	 */
	public Vector<Vector<Object>> getData() {
		return data;
	}
	
	/**
	 * @param file
	 */
	public void setData(ArrayList<String> dtdNames, int[][]stats) {
		for(int i=0; i<dtdNames.size();i++){
			Vector<Object> temp = new Vector<Object>();
			String dtdName = dtdNames.get(i);
			temp.add(dtdName);
			for(int j=0; j<stats[i].length;j++){
				temp.add(stats[i][j]);
			}
			data.add(temp);
		}
	}	
	
	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	public int getColumnCount() {
        return columnNames.length;
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getRowCount()
     */
    public int getRowCount() {
        return data.size();
    }

    /* (non-Javadoc)
     * @see javax.swing.table.AbstractTableModel#getColumnName(int)
     */
    public String getColumnName(int col) {
        return columnNames[col];
    }

    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    public Object getValueAt(int row, int col) {
        return data.get(row).get(col);
    }

    /*
     * This table's editable.
     */
    public boolean isCellEditable(int row, int col) {
//        if (col < 2) {
            return false;
//        } else {
//            return true;
//        }
    }

    /*
     * This table's data can change.
     */
    public void setValueAt(Object value, int row, int col) {
        if (DEBUG) {
            System.out.println("Setting value at " + row + "," + col
                               + " to " + value
                               + " (an instance of "
                               + value.getClass() + ")");
        }

        data.get(row).set(col, value);
        fireTableCellUpdated(row, col);

        if (DEBUG) {
            System.out.println("New value of data:");
            printDebugData();
        }
    }
    
    /**
     * 
     */
    private void printDebugData() {
        int numRows = getRowCount();
        int numCols = getColumnCount();

        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + data.get(i).get(j));
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }
	
}
